<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择学生状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_student_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学生名字" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入学生名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="校区" prop="campus">
        <el-select v-model="queryParams.campus" placeholder="请选择校区" clearable>
          <el-option
            v-for="dict in dict.type.sys_campus_choose"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="模拟面试" prop="mockInterview">
        <el-select v-model="queryParams.mockInterview" placeholder="请选择模拟面试" clearable>
          <el-option
            v-for="dict in dict.type.sys_test_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="结业测试" prop="finalTest">
        <el-select v-model="queryParams.finalTest" placeholder="请选择结业测试" clearable>
          <el-option
            v-for="dict in dict.type.sys_test_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['student:studentMessage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          size="mini"
          :disabled="multiple"
          @click="handleStateUpdate"
        >状态修改</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          size="mini"
          :disabled="single"
          @click="handleStateClass"
        >留级转班</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          size="mini"
          :disabled="single"
          @click="handleInsertTrack"
        >添加跟踪</el-button>

      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['student:studentMessage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['student:studentMessage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['student:studentMessage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--跟踪记录对话框-->
    <el-dialog :title="title" :visible.sync="openTrackRecord" width="500px" append-to-body>
      <el-timeline v-for="trackRecord in trackRecords">
        <el-timeline-item :timestamp="trackRecord.happenTime" placement="top">
          <el-card>
            <h4>跟踪人：[{{ trackRecord.traceTeacher}}]</h4>
            <p>情况说明：{{trackRecord.remark	}}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>

<!--列表展示-->
    <el-table v-loading="loading" :data="studentMessageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="序号" align="center" prop="id" />-->

      <el-table-column label="学生名字" align="center" prop="name" />
      <el-table-column label="所属班级" align="center" prop="grade.name" />
      <el-table-column label="校区" align="center" prop="campus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_campus_choose" :value="scope.row.campus"/>
        </template>
      </el-table-column>
      <el-table-column label="学生状态" align="center" prop="state">
        <template slot-scope="scope">
          <el-select v-model="scope.row.state" :value="form.state" id="updateForm" @change="handleStudentUpdate(scope.row)">
            <el-option
              v-for="dict in dict.type.sys_student_state"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="模拟面试" align="center" prop="mockInterview">
        <template slot-scope="scope">
          <el-select v-model="scope.row.mockInterview" :value="form.mockInterview" id="updateForm" @change="handleStudentUpdate(scope.row)">
            <el-option
              v-for="dict in dict.type.sys_simulation_interview"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </template>
      </el-table-column>

      <el-table-column label="结业测试" align="center" prop="finalTest">
        <template slot-scope="scope">
          <el-select v-model="scope.row.finalTest" :value="form.finalTest" id="updateForm" @change="handleStudentUpdate(scope.row)">
            <el-option
              v-for="dict in dict.type.sys_final_test"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="trackRecord(scope.row)"
          >跟踪记录</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['student:studentMessage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['student:studentMessage:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="insertAttention(scope.row)"
          >关注</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加学生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生名字" prop="name">
          <el-input v-model="form.name" placeholder="请输入学生名字" />
        </el-form-item>
        <el-form-item label="电话号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话号码" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属班级" prop="classId">
          <el-select v-model="form.classId" placeholder="请选择班级">
            <el-option
              v-for="dict in className"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学历" prop="educationBackground">
          <el-input v-model="form.educationBackground" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入学校" />
        </el-form-item>
        <el-form-item label="父母电话" prop="parentPhone">
          <el-input v-model="form.parentPhone" placeholder="请输入父母电话" />
        </el-form-item>
        <el-form-item label="学生状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_state"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="校区" prop="campus">
          <el-select v-model="form.campus" placeholder="请选择校区">
            <el-option
              v-for="dict in dict.type.sys_campus_choose"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="mockInterview">
          <el-select v-model="form.mockInterview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_simulation_interview"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结业测试" prop="finalTest">
          <el-select v-model="form.finalTest" placeholder="请选择结业测试">
            <el-option
              v-for="dict in dict.type.sys_final_test"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--修改学生信息对话框-->
    <el-dialog :title="title" :visible.sync="openUpdate" width="500px" append-to-body>
      <el-form ref="formEdit" :model="formEdit" :rules="rules" label-width="80px">
        <el-form-item label="学生名字" prop="name">
          <el-input v-model="formEdit.name" placeholder="请输入学生名字" />
        </el-form-item>
        <el-form-item label="所属班级" prop="classId">
          <el-select v-model="formEdit.classId" placeholder="请选择班级">
            <el-option
              v-for="dict in className"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生状态" prop="state">
          <el-select v-model="formEdit.state" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_state"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="校区" prop="campus">
          <el-select v-model="formEdit.campus" placeholder="请选择校区">
            <el-option
              v-for="dict in dict.type.sys_campus_choose"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="mockInterview">
          <el-select v-model="formEdit.mockInterview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_test_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结业测试" prop="finalTest">
          <el-select v-model="formEdit.finalTest" placeholder="请选择结业测试">
            <el-option
              v-for="dict in dict.type.sys_test_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateSubmitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--状态修改对话框-->
    <el-dialog :title="title" :visible.sync="openStateUpdate" width="500px" append-to-body>
      <el-form ref="updateStateForm" :model="updateStateForm" :rules="rules" label-width="80px">
        <el-form-item label="学生状态" prop="state">
          <el-select v-model="updateStateForm.state" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_state"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="mockInterview">
          <el-select v-model="updateStateForm.mockInterview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_test_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结业测试" prop="finalTest">
          <el-select v-model="updateStateForm.finalTest" placeholder="请选择结业测试">
            <el-option
              v-for="dict in dict.type.sys_test_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateStateSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--转班留级对话框-->
    <el-dialog :title="title" :visible.sync="openUpdateClass" width="500px" append-to-body>
      <el-form ref="updateStateClass" :model="updateStateClass" :rules="rules" label-width="90px">
        <el-form-item label="姓名：" prop="updateStateClass.name">
          <el-input type="text" v-model="updateStateClass.name" :disabled="true"
                    size="mini" style="width:180px;" >
          </el-input>
        </el-form-item>
        <el-form-item label="转入班级" prop="state">
          <el-select v-model="updateStateClass.className" placeholder="请选择转入班级">
            <el-option
              v-for="dict in className"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生状态：" prop="updateStateClass.state">
          <el-input type="text" v-model="updateStateClass.state" :disabled="true"
                    size="mini" style="width:180px;" >
          </el-input>
        </el-form-item>
        <el-form-item label="备注：" prop="updateStateClass.node">
          <el-input type="text" v-model="updateStateClass.node" size="mini" style="width:180px;height: 100px" >
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateStateClassSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--添加跟踪对话框-->
    <el-dialog :title="title" :visible.sync="openInsertTrack" width="500px" append-to-body>
      <el-form ref="insertTrackForm" :model="insertTrackForm" :rules="rules" label-width="90px">
        <el-form-item label="问题类型" prop="state">
          <el-select v-model="insertTrackForm.problemType" placeholder="请选择问题类型">
            <el-option
              v-for="dict in dict.type.sys_problem_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发生时间" prop="insertTrackForm.happenTime">
          <el-date-picker clearable
                          v-model="insertTrackForm.happenTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择开班时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="扣除分数：" prop="insertTrackForm.socre">
          <el-input type="text" v-model="insertTrackForm.socre"  placeholder="请输入扣除分数">
          </el-input>
        </el-form-item>
        <el-form-item label="问题描述：" prop="insertTrackForm.remark">
          <el-input type="textarea" :rows="2" v-model="insertTrackForm.remark" placeholder="请输入备注">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="insertTrackSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--添加关注对话框-->
    <el-dialog :title="title" :visible.sync="openInsertAttention" width="500px" append-to-body>
      <el-form ref="insertAttentionForm" :model="insertAttentionForm" :rules="rules" label-width="90px">

        <el-form-item label="姓名：" prop="insertAttentionForm.name">
          <el-input type="text" v-model="insertAttentionForm.studentName" :disabled="true"
                    size="mini" style="width:180px;" >
          </el-input>
        </el-form-item>
        <el-form-item label="负责老师" prop="insertAttentionForm.teacherName">
          <el-select v-model="insertAttentionForm.teacherName" placeholder="请选择负责老师">
            <el-option
              v-for="dict in teacherNames"
              :key="dict.name"
              :label="dict.name"
              :value="dict.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="困难系数" prop="insertAttentionForm.difficulty">
          <el-select v-model="insertAttentionForm.difficulty" placeholder="请选择困难系数">
            <el-option
              v-for="dict in dict.type.sys_difficult_coefficient"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注：" prop="insertAttentionForm.remark">
          <el-input type="textarea" :rows="2" v-model="insertAttentionForm.node" placeholder="请输入备注">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="insertAttentionSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>

import { listStudentMessage, getStudentMessage, delStudentMessage, addStudentMessage, updateStudentMessage,
  listClassName,updateBatchStudentMessage,getDicts,updateStateClass,insertTrack , getTrackRecord} from "@/api/student/studentMessage";
import {addAttention, listTeacherManagement} from "@/api/eduadmin/attention";
export default {
  name: "StudentMessage",
  dicts: ['sys_student_state', 'sys_test_state', 'sys_campus_choose','sys_user_sex','sys_problem_type','sys_difficult_coefficient','sys_simulation_interview','sys_final_test'],
  data() {
    return {
      //跟踪记录
      trackRecords:[],
      id:null,
      //班级名称
      className:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      teacherNames:[],
      total: 0,
      // 学生信息表格数据
      studentMessageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openUpdate:false,
      openStateUpdate: false,
      openUpdateClass:false,
      openInsertTrack:false,
      openTrackRecord:false,
      openInsertAttention:false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        state: null,
        name: null,
        classId: null,
        campus: null,
        mockInterview: null,
        finalTest: null
      },
      form:{
        name:null,
        phone:null,
        age:null,
        sex:null,
        classId:null,
        educationBackground:null,
        major:null,
        school:null,
        parentPhone:null,
        state:null,
        campus:null,
        mockInterview:null,
        finalTest:null,
      },
      // 表单参数
      formEdit: {
        id: null,
        state: null,
        name: null,
        classId: null,
        campus: null,
        mockInterview: null,
        finalTest: null,
        classname: null,
        age: null
      },
      /** 修改状态表单*/
      updateStateForm:{
        ids:[],
        state:null,
        mockInterview: null,
        finalTest: null
      },
      /** 转班留级表单*/
      updateStateClass:{
        id:null,
        name:null,
        className:null,
        state:null,
        node:null,
      },
     /** 添加跟踪表单*/
     insertTrackForm:{
        id: null,
        problemType: null,
        happenTime: null,
        socre: null,
        remark: null,
      },
     /** 跟踪记录对话框数据*/
      trackRecordForm:{
        studentName:null,
        happenTime:null,
        traceTeacher:null,
        remark:null,
     },
      /** 添加关注对话框数据*/
      insertAttentionForm:{
        id:null,
        className:null,
        studentId:null,
        studentName:null,
        teacherName:null,
        difficulty:null,
        state:null,
        mockInterview:null,
        finalTest:null,
        node:null,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    /*查询所有班级*/
    this.getClassName();
  },
  methods: {
    /** 查询所有班级*/
    getClassName(){
      listClassName().then(response=>{
        this.className=response.rows;
        console.log(this.className)
      });
    },
    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      listStudentMessage(this.queryParams).then(response => {
        this.studentMessageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openUpdate = false;
      this.openStateUpdate =false;
      this.openUpdateClass = false;
      this.openInsertTrack = false;
      this.openTrackRecord =false;
      this.openInsertAttention = false;
      this.reset();
    },
    /** 表单重置*/
    reset() {
      this.formEdit = {
        id: null,
        state: null,
        name: null,
        classId: null,
        campus: null,
        mockInterview: null,
        finalTest: null,
        classname: null,
        age: null
      };
      this.resetForm("formEdit");
    },


    /** 添加表单重置*/
    resetadd(){
      this.form = {
          name:null,
          phone:null,
          age:null,
          sex:null,
          classId:null,
          educationBackground:null,
          major:null,
          school:null,
          parentPhone:null,
          state:null,
          campus:null,
          mockInterview:null,
          finalTest:null,
      };
    },
    /** 状态修改表单重置*/
    resetUpdate(){
      this.updateStateForm = {
        ids:[],
        state:null,
        mockInterview: null,
        finalTest: null
      };
    },
    /** 转班留级表单重置*/
    resetUpdateClass(){
      this.updateStateClass = {
        id:null,
        name:null,
        className:null,
        state:null,
        node:null,
      };
    },
    /** 添加跟踪表单重置*/
    restInsertTrackForm(){
      this.insertTrackForm = {
        id: null,
        problemType: null,
        happenTime: null,
        socre: null,
        remark: null,
      }

    },
    /** 添加关注表单重置*/
    restInsertAttentionForm(){
      this.insertAttentionForm = {
        id:null,
        className:null,
        studentName:null,
        studentId:null,
        teacherName:null,
        difficulty:null,
        state:null,
        mockInterview:null,
        finalTest:null,
        node:null,
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.resetadd();
      this.open = true;
      this.title = "添加学生信息";
      console.log(123)
    },
    /** 状态修改按钮操作*/
    handleStateUpdate(){
      this.resetUpdate();
      this.openStateUpdate = true;
      this.title = "修改学生状态";
    },

    /** 留级转班按钮操作*/
    handleStateClass(){
      this.resetUpdateClass();
      this.openUpdateClass = true;
      getStudentMessage(this.ids).then(response=>{
        this.title = response.data.name + "转班处理";
        this.updateStateClass.name = response.data.name;
        // this.updateStateClass.state = response.data.state;
      })
      this.getDicts("sys_student_state").then(response=>{
        this.updateStateClass.state = response.data[2].dictLabel;
      })
    },
    /** 添加跟踪按钮操作*/
    handleInsertTrack(){
      this.restInsertTrackForm();
      this.openInsertTrack = true;
      getStudentMessage(this.ids).then(response=>{
        this.title = response.data.name + "添加问题跟踪记录";
      })
      this.getDicts("sys_student_state").then(response=>{
        this.updateStateClass.state = response.data[2].dictLabel;
      })

    },
    /** 修改学生状态*/
    handleStudentUpdate(row){
      updateStudentMessage(row).then(response=>{
      })
    },



    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStudentMessage(id).then(response => {
        this.formEdit = response.data;
        this.openUpdate = true;
        this.title = "修改学生信息";
      });
    },
    /** 跟踪记录按钮操作*/
    trackRecord(row) {
      this.openTrackRecord = true;
      const id = row.id
      getTrackRecord(id).then(response => {
        this.trackRecords = response;
        this.title = this.trackRecords[0].studentName+ "的跟踪记录";
      });
    },
    /** 关注按钮操作*/
    insertAttention(row){
      this.restInsertAttentionForm();
      this.openInsertAttention = true;
      const id = row.id
      getStudentMessage(id).then(response =>{
        this.insertAttentionForm.studentId = response.data.id
        this.insertAttentionForm.className = response.data.grade.name
        // console.log(this.insertAttentionForm.className)
        this.insertAttentionForm.studentName = response.data.name
        this.insertAttentionForm.state = response.data.state
        this.insertAttentionForm.mockInterview = response.data.mockInterview
        this.insertAttentionForm.finalTest =response.data.finalTest
        this.title = response.data.name + "加入重点关注";
        console.log(this.insertAttentionForm)
      });
      listTeacherManagement().then(response =>{
        this.teacherNames = response.rows
        // console.log(response.rows)
        for (let i in a){
          this.teacherNames[i] = a[i].name;
        }
        this.insertAttentionForm.teacherName =this.teacherNames
        // console.log(this.teacherNames);
        // this.insertAttentionForm.teacherName = response
      })
    },
    /** 状态修改提交按钮*/
    updateStateSubmit(row){
      this.$refs["updateStateForm"].validate(valid=>{
        let a = this.updateStateForm;
        if (valid){
          const ids = row.id || this.ids;
          this.$modal.confirm('是否确认修改学生信息编号为"' + ids + '"的数据项？').then(function() {
            a.ids = ids;
            console.log(a)
            return updateBatchStudentMessage(a);
          }).then(() => {
            this.openStateUpdate =false;
            this.getList();
            this.$modal.msgSuccess("修改成功");
          }).catch(() => {
            alert("111");
            this.openStateUpdate =false;
          });
        }
      })
    },
    /** 转班留级提交按钮*/
    updateStateClassSubmit(){
      console.log(this.ids)
      this.$refs["updateStateClass"].validate(valid=>{
        let a = this.updateStateClass;
        if (valid){
          const ids =  this.ids;
          this.$modal.confirm('是否确认该学生留级转班，编号为"' + ids + '"的数据项？').then(function() {
            a.id = ids;
            return updateStateClass(a);
          }).then(() => {
            this.openUpdateClass =false;
            this.getList();
            this.$modal.msgSuccess("转班成功");
          }).catch(() => {
            alert("111");
            this.openUpdateClass =false;
          });
        }
      })
    },
    /** 添加跟踪提交按钮*/
    insertTrackSubmit(){
      console.log(this.ids)
      this.$refs["insertTrackForm"].validate(valid=>{
        let a = this.insertTrackForm;
        if (valid){
          const ids =  this.ids;
          this.$modal.confirm('是否确认添加该学生跟踪记录，编号为"' + ids + '"的数据项？').then(function() {
            a.id = ids;
            return insertTrack(a);
          }).then(() => {
            this.openInsertTrack =false;
            this.getList();
            this.$modal.msgSuccess("添加跟踪成功");
          }).catch(() => {
            this.openInsertTrack =false;
          });
        }
      })
    },
    /** 添加关注提交按钮*/
    insertAttentionSubmit(row){
      console.log(row.id)
      this.$refs["insertAttentionForm"].validate(valid=>{
        let a = this.insertAttentionForm;
        if (valid){
          const id =  row.id;
          console.log(id)
          this.$modal.confirm('是否确认将该学生添加重点关注跟踪记录，编号为"' + id + '"的数据项？').then(function() {
            a.id = id;
            return addAttention(a);
          }).then(() => {
            this.openInsertAttention =false;
            this.getList();
            this.$modal.msgSuccess("添加关注成功");
          }).catch(() => {
            this.openInsertAttention =false;
          });
        }
      })
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        console.log(valid)
        if (valid) {
            console.log("111")
            addStudentMessage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
    /** 修改按钮操作*/
    updateSubmitForm() {
      this.$refs["formEdit"].validate(valid => {
        console.log(valid)
        if (valid) {
          if (this.formEdit.id != null) {
            console.log("111")
            updateStudentMessage(this.formEdit).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openUpdate = false;
              this.open = false;
              this.getList();
            });
          }
        }
      })
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学生信息编号为"' + ids + '"的数据项？').then(function() {
        return delStudentMessage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('student/studentMessage/export', {
        ...this.queryParams
      }, `studentMessage_${new Date().getTime()}.xlsx`)
    }

    },


};
</script>
